package com.ruoyi.web.controller.glyh;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.glyh.domain.MaintenanceInfo;
import com.ruoyi.glyh.service.IMaintenanceInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 养护信息Controller
 * 
 * @author wenjie
 * @date 2024-06-08
 */
@RestController
@RequestMapping("/glyh/mainInfo")
public class MaintenanceInfoController extends BaseController {
	@Autowired
	private IMaintenanceInfoService maintenanceInfoService;

	/**
	 * 查询养护信息列表
	 */
	@PreAuthorize("@ss.hasPermi('glyh:mainInfo:list')")
	@GetMapping("/list")
	public TableDataInfo list(MaintenanceInfo maintenanceInfo) {
		startPage();
		List<MaintenanceInfo> list = maintenanceInfoService.selectMaintenanceInfoList(maintenanceInfo);
		return getDataTable(list);
	}

	/**
	 * 导出养护信息列表
	 */
	@PreAuthorize("@ss.hasPermi('glyh:mainInfo:export')")
	@Log(title = "养护信息", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, MaintenanceInfo maintenanceInfo) {
		List<MaintenanceInfo> list = maintenanceInfoService.selectMaintenanceInfoList(maintenanceInfo);
		ExcelUtil<MaintenanceInfo> util = new ExcelUtil<MaintenanceInfo>(MaintenanceInfo.class);
		util.exportExcel(response, list, "养护信息数据");
	}

	/**
	 * 获取养护信息详细信息
	 */
	@PreAuthorize("@ss.hasPermi('glyh:mainInfo:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id) {
		return success(maintenanceInfoService.selectMaintenanceInfoById(id));
	}

	/**
	 * 新增养护信息
	 */
	@PreAuthorize("@ss.hasPermi('glyh:mainInfo:add')")
	@Log(title = "养护信息", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody MaintenanceInfo maintenanceInfo) {
		String username = getUsername();
		maintenanceInfo.setCreateBy(username);
		maintenanceInfo.setUpdateBy(username);
		return toAjax(maintenanceInfoService.insertMaintenanceInfo(maintenanceInfo));
	}

	/**
	 * 修改养护信息
	 */
	@PreAuthorize("@ss.hasPermi('glyh:mainInfo:edit')")
	@Log(title = "养护信息", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody MaintenanceInfo maintenanceInfo) {
		String username = getUsername();
		maintenanceInfo.setUpdateBy(username);
		return toAjax(maintenanceInfoService.updateMaintenanceInfo(maintenanceInfo));
	}

	/**
	 * 删除养护信息
	 */
	@PreAuthorize("@ss.hasPermi('glyh:mainInfo:remove')")
	@Log(title = "养护信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(maintenanceInfoService.deleteMaintenanceInfoByIds(ids));
	}
}
